package jp.co.hcs.attendancemanagement.inputtableb.action;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jp.co.hcs.attendancemanagement.action.AMAction;
import jp.co.hcs.attendancemanagement.data.entity.Work;
import jp.co.hcs.attendancemanagement.inputtableb.logic.CheckWorkCodeLogic;
import net.sf.json.JSONObject;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class CheckExistWorkCodeAction extends AMAction {
  public ActionForward executeImpl(ActionMapping mapping, ActionForm form,
      HttpServletRequest request, HttpServletResponse response) throws Exception {

    String workCode = (String) request.getParameter("workCode");
    if (workCode == null) {
      return null;
    }

    response.setContentType("text/json");
    CheckWorkCodeLogic checkWorkCodeLogic = CheckWorkCodeLogic.getInstance();
    Work workObj = checkWorkCodeLogic.checkWorkCodeExisting(workCode);
    JSONObject jsonObj = JSONObject.fromObject(workObj);
    PrintWriter pw = response.getWriter();
    pw.write(jsonObj.toString());
    pw.flush();
    pw.close();
    return null;
  }
}
